import { MARRIAGE_BASE_STATUS, GENDER_BASE, ID_TYPE, RELATIONSHIP, PDF_NAME } from './constant';

/**
 * @param arr 字典列表
 * @param keyName 键名
 * @example
 *  const workStatus = [ {id: 0, name: '在职'}, {id: 1, name: '退休'} ]
    arr2Map(workStatus) => {0: {id: 0, name: '在职'}, 1: {id: 1, name: '退休'}}
 */
export function arr2Map(arr, keyName = 'id') {
  return arr.reduce(function (p, n) {
    p[n[keyName]] = n;
    return p;
  }, {});
}

/**
 * 婚姻状态
 */
export const marriageBaseStatus = [
  { id: MARRIAGE_BASE_STATUS.Unmarriage, i18nKey: 'common.marriage_status.unmarriage', name: '未婚' },
  { id: MARRIAGE_BASE_STATUS.Marriaged, i18nKey: 'common.marriage_status.marriaged', name: '已婚' },
];

export const marriageBaseStatusMap = arr2Map(marriageBaseStatus);

/**
 * 性别
 */
export let genderBase = [
  { id: GENDER_BASE.Male, i18nKey: 'common.genter.male', name: '男' },
  { id: GENDER_BASE.Female, i18nKey: 'common.genter.female', name: '女' },
];

export let genderBaseMap = arr2Map(genderBase);

/**
 * 证件类型
 */
export const idType = [
  { key: ID_TYPE.IdCard, i18nKey: 'common.id_type.id_card', name: '身份证' },
  { key: ID_TYPE.Passport, i18nKey: 'common.id_type.passport', name: '护照' },
  { key: ID_TYPE.HmCard, i18nKey: 'common.id_type.hm_card', name: '港澳身份证' },
  { key: ID_TYPE.GAT, i18nKey: 'common.id_type.gat', name: '港澳通行证' },
  { key: ID_TYPE.OfficeCert, i18nKey: 'common.id_type.office_cert', name: '军官证' },
  { key: ID_TYPE.TaiWanIdCard, i18nKey: 'common.id_type.taiwan_id_card', name: '台胞证' },
  { key: ID_TYPE.Other, i18nKey: 'common.id_type.other', name: '其他' },
];

export const idTypeMap = arr2Map(idType, 'key');

/**
 * 认证证件类型
 */
export const authIdType = [
  {
    key: ID_TYPE.EmployeeId,
    i18nKey: 'common.id_type.employee_id',
    name: '员工号',
  },
  ...idType,
];

export const authIdTypeMap = arr2Map(authIdType, 'key');

/**
 * 体检人关系枚举
 */
export const relationship = [
  { id: RELATIONSHIP.Self, i18nKey: 'common.relationship.self', name: '本人' },
  { id: RELATIONSHIP.Spouses, i18nKey: 'common.relationship.spouses', name: '配偶' },
  { id: RELATIONSHIP.Children, i18nKey: 'common.relationship.children', name: '子女' },
  { id: RELATIONSHIP.Mother, i18nKey: 'common.relationship.mother', name: '母亲' },
  { id: RELATIONSHIP.Father, i18nKey: 'common.relationship.father', name: '父亲' },
  { id: RELATIONSHIP.BrotherOrSister, i18nKey: 'common.relationship.brother_or_sister', name: '兄弟姐妹' },
  { id: RELATIONSHIP.RelativeOrFirend, i18nKey: 'common.relationship.relative_or_firend', name: '亲戚朋友' },
  { id: RELATIONSHIP.Other, i18nKey: 'common.relationship.other', name: '其他' },
];

export const relationshipMap = arr2Map(relationship);

/**
 * oss pdf
 */
export const pdf = [
  {
    name: PDF_NAME.PrivacyPolicy,
    path: 'http://mytijian-img.oss-cn-hangzhou.aliyuncs.com/file/pdf/privacy-policy.pdf',
  },
  { name: PDF_NAME.UserProtocal, path: 'http://mytijian-img.oss-cn-hangzhou.aliyuncs.com/file/pdf/user-protocol.pdf' },
  { name: PDF_NAME.JdExamManual, path: 'http://mytijian-img.oss-cn-hangzhou.aliyuncs.com/file/pdf/jd-exam-manual.pdf' },
  {
    name: PDF_NAME.ZiruHealthbook,
    path: 'http://mytijian-img.oss-cn-hangzhou.aliyuncs.com/file/pdf/ziru-healthbook.pdf',
  },
];

export const pdfMap = arr2Map(pdf, 'name');
